﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XSTDZ.ERP.Core.Generator;
using XSTDZ.ERP.Core.Extentions;


namespace XSTDZ.ERP.Domain.Models
{
    /// <summary>
    /// 盘点
    /// </summary>
    public partial class ProductCheckBill
    {
        public ProductCheckBill()
        {
            this.ProductCheckBillDetail = new HashSet<ProductCheckBillDetail>();
        }
        public ProductCheckBill InitProductCheck()
        {
            if (this.Id.Equals(Guid.Empty))
            {
                this.Id = (Guid)new SequentialIdentityGenerator().Next;
            }
            this.CreateTime = DateTime.Now;
            this.Deleted = 0;
           
            return this;
        }

        public ProductCheckBill AddProductCheckDetails(ProductCheckBillDetail detail)
        {
            if (!this.ProductCheckBillDetail.Contains(detail))
            {
                if (detail.ProductCheckBillID == null || detail.ProductCheckBillID.Equals(Guid.Empty))
                {
                    detail.ProductCheckBillID = this.Id;
                }
                this.ProductCheckBillDetail.Add(detail.InitProductCheck());
            }
            return this;
        }
       
        public ProductCheckBill AddProductCheckDetails(IEnumerable<ProductCheckBillDetail> details)
        {
            details.Each(d => AddProductCheckDetails(d));
            return this;
        }

        public ProductCheckBill ClearAllChildren()
        {
            this.ProductCheckBillDetail.Clear();
            return this;
        }
    }
}
